<template>
	<PopupTemplate className="swiper_popup" :title="title" :type="title?1:2" :visible="visible"
		@update:visible="handleUpdate">
		<view class="content_container width_300 pt_36">
			<view class="mtafter_12" v-for="item,index in list" :key="index">
				<Coupon :isReceive="true" width="600rpx" :data="item" :showBtn="false"></Coupon>
			</view>
			<button class="custom_btn primary lh_40 w-100 fz_14 br_27 mt_32" @click.stop="handleReceive">一键领取</button>
			<view class="mt_26 ptb_8 fc_999 fb fc" @click.stop="$emit('update:visible', false)">
				暂不领取
			</view>
		</view>
	</PopupTemplate>
</template>

<script>
	import api from '@/service/config/api.js'
	import PopupTemplate from '@/components/PopupTemplate'
	import Coupon from '@/components/order/Coupon.vue'
	export default {
		components: {
			PopupTemplate,
			Coupon
		},
		props: {
			visible: {
				type: Boolean,
				default: false
			},
			list: {
				type: Array,
				default: () => ([])
			}
		},
		data() {
			return {
				title: '优惠券',
				platformInfo: this.$storage.getItem('platformInfo') || {},
			}
		},
		methods: {
			handleUpdate(e) {
				this.$emit('update:visible', e)
			},
			handleReceive() {
				this.$utils.loading()
				api.get('/marketing/applet/api/platform/discount_coupon/oneClick/receive', {
					dealerId: this.$store.state.functionRange,
					receivePlatform: this.platformInfo.id
				}).then(res => {
					this.$utils.showToast('领取成功',1500,0,'','success')
					this.$emit('update:visible', false)
				})
			}
		}
	}
</script>

<style>
	.content_container {
		max-height: 600rpx;
		overflow-y: auto;
	}
</style>